package de.hska.pwmanager.persistence.model;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity
public class PasswordData {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	private String notes;
	@ManyToOne
	private PasswordCategory passwordCategory;
	@OneToMany(cascade=CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<PasswordUserHash> passwordUserHashs = new ArrayList<PasswordUserHash>();
	private String title;
	private String username;
	
	public String getUsername() {
		return username;
	}

	public PasswordData setUsername(String username) {
		this.username = username;
		return this;
	}

	public Long getId() {
		return id;
	}

	public String getNotes() {
		return notes;
	}

	public PasswordCategory getPasswordCategory() {
		return passwordCategory;
	}

	public List<PasswordUserHash> getPasswordUserHashs() {
		return passwordUserHashs;
	}

	public String getTitle() {
		return title;
	}

	public PasswordData setId(Long id) {
		this.id = id;
		return this;
	}

	public PasswordData setNotes(String notes) {
		this.notes = notes;
		return this;
	}

	public PasswordData setPasswordCategory(PasswordCategory passwordCategory) {
		this.passwordCategory = passwordCategory;
		return this;
	}

	public PasswordData setPasswordUserHashs(
			List<PasswordUserHash> passwordUserHashs) {
		this.passwordUserHashs = passwordUserHashs;
		return this;
	}

	public PasswordData setTitle(String title) {
		this.title = title;
		return this;
	}
	
	@Override
	public boolean equals(Object object) {
		if(object instanceof PasswordData) {
			PasswordData another = (PasswordData)object;
			return (another.getId()==this.getId());
		}
		return false;
	}
}
